Algorithm capacity

By Evgenia "Jenny" Nitishinskaya and Delaney Granizo-Mackenzie

Part of the Quantopian Lecture Series:

Notebook released under the Creative Commons Attribution 4.0 License.


When taking an algorithm out into the real world, there are many factors which limit the amount of capital it can run on both above and below. This is referred to as algorithm capacity. Below, we discuss some of these factors and how they affect the range of capital at which an algorithm is functional.

Slippage and liquidity

Buying a stock pushes its price up, and selling it drives the price down. This effect is called slippage. It occurs even as we are making the trade: if we order 10 shares of a stock, but the seller offering it at the lowest price is only selling 8, then the last two shares will have to be bought from a different seller at a higher price. This is very common, and can result in a total price very different from the one we originally thought we were buying at.

The impact of our transaction on the price depends on the size of our order relative to the current trading volume. Placing a small order for a liquid (highly traded) stock will incur less slippage than placing a large order for an illiquid stock. This limits the amount of capital we can put into our algorithm: if the slippage is too high, the unexpected changes in the stock price will cancel out the profit we expected to make. We can stop the algorithm from paying too much by placing a limit order, which will only sell above (buy below) a specified price.

However, placing a limit order means that we will not be able to get as much of the stock as we desired. Relatedly, if a stock is illiquid, we might not be able to fill an order for a long time. This is troublesome for most strategies, particularly high-frequency ones and those that rely on precise holdings. All of these factors mean that each strategy has a maximum capacity beyond which it does not function properly.

No fractional shares

Shares can only be bought in whole units, but algorithms often specify a dollar amount to be bought, which is rounded down to the nearest whole share. If we are buying many shares, one more or one fewer doesn't make a large difference. However, if our strategy is running on a small amount of capital, a fraction of a share is a significant amount of the holdings we anticipated having, so the reality will be far from what we intended. Our algorithm's sensitivity to such errors and the prices of the stocks we are investing in determine the minimum algorithm capacity below which it cannot run.

Minimum transaction fee

Every time we execute a transaction, we must pay our broker a transaction fee (also known as commission). These are never fun, and can render whole strategies completely useless. They are especially bad for algorithms that make many small trades. This is because transaction fees are generally smaller for smaller transactions, but there is a minimum fee that all transactions below a certain amount have to pay.

Say the transaction fee is just 0.1% of the money involved in the transaction at while we are running a large amount of capital. However, there is be a \$1 fee minimum. Then the transaction fee will be higher than 0.1% when we make a trade for less than \$1000. Eventually \$1 will be more than we expect the profit on the transaction to be. That's definitely not something we want, so minimum transaction fees enforce a minimum capacity for our algorithm.

Margin restrictions

Many brokers will not allow borrowing money if we have less than a certain amount in our portfolio; the precise rules vary depending on the broker and the type of portfolio. This restricts us in a number of ways. For example, we cannot buy if we have insufficient funds, even if we sell at the same time to cover the cost. We must wait (days) for the money from the sell order to be transferred before we can place the buy order. This means that our algorithm cannot execute the trades it wants if we do not invest enough capital in it. Alternatively, it can be a cap on our algorithm's capacity if we keep a lot of cash uninvested in order to be able to buy when we want.

Conclusion

All of the factors above are built into the Quantopian backtester (except for the last, which you can model yourself). You can adjust the slippage and commission models to try out different scenarios. However, the true effects cannot be seen from backtesting or paper-trading, especially slippage. The best approach is to test that your algorithm is robust for a range of models at your intended capital allocation before turning it live.